package cn.stalk.wf.common;

import lombok.AllArgsConstructor;
import lombok.Getter;
import lombok.NoArgsConstructor;
import lombok.extern.slf4j.Slf4j;

@Slf4j
@Getter
@AllArgsConstructor
@NoArgsConstructor
public class Response {

    private boolean success;
    private String message;
    private Object data;

    public static Response successMessage(String message) {
        return new Response(true, message, null);
    }

    public static Response successData(Object data) {
        return new Response(true, null, data);
    }

    public static Response success(String message, Object data) {
        return new Response(true, message, data);
    }

    public static Response failedMessage(String message) {
        return new Response(false, message, null);
    }

    public static Response failed(String message, Object data) {
        return new Response(false, message, data);
    }

    public static Response failedException(Throwable e) {
        log.error("response error.", e);
        
        String message = null;
        if (e instanceof NullPointerException) {
            message = "NullPointerException";
        } else {
            message = e.getMessage();
        }
        return new Response(false, message, null);
    }
}
